# 将错误信息打印到文件
tofile = None
try:
    tofile = open('异常.txt', 'r', encoding='utf-8')
    tofile.write("人生苦短，谁用Python。。。")
except Exception as error:
    print("写入文件失败", error)
finally:
    tofile.close()
    print("文件已关闭")
